const DB = require('../../../utils/db')
// 引入jwt token工具
const JwtUtil = require('../../../utils/jwt')
/**
 * POST
 * 发表一个帖子
 */
module.exports = async (ctx) => {
  // 获取token
  let token = ctx.request.header.authorization
  let jwt = new JwtUtil(token)
  // 用token获取到userid
  let userid = jwt.verifyToken()
  // console.log(ctx.request.body)
  let params = ctx.request.body
  console.log(typeof params.imgArr)
  // try {
    const res = await DB.query(
      `insert into dynamic(userid, createTime, updateTime, label, textContent, imgUrl,title, commentTotal) values('${userid}', now(), now(),'${params.label}','${params.text}','${params.imgArr}','${params.title}', 0)`
    )
  // } catch {
  //   ctx.body = {
  //     code: 0,
  //     data: '错误',
  //   }
  //   return
  // }
  console.log(res)
  ctx.body = {
    code: 0,
    data: '发布成功',
  }
}
